package com.styytech.dadabao.widge.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.styytech.dadabao.R;


public class CameraDialog {
	private Dialog mDialog;
    private TextView tv_dialog_title,tv_dialog_text;
    private TextView tv_camera,tv_photo,tv_cancel;
    private Context mContext;
    private View view;
      
    Dialogcallback cameracallback,photocallback,canceldialogcallback;
   
    public CameraDialog (Context context){
        this.mContext=context;

        initViews();
    }
  
    private void initViews(){
        mDialog = new Dialog(mContext,
                R.style.camera_dialog);
        LayoutInflater layoutInflater=(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.dialog_camera, null);
        tv_camera=(TextView)view.findViewById(R.id.tv_camera);
        tv_photo=(TextView)view.findViewById(R.id.tv_photo);
        tv_cancel=(TextView)view.findViewById(R.id.tv_cancel);
        tv_camera.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
            	cameracallback.dialogdo();
            }
        });
        tv_photo.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				photocallback.dialogdo();
			}
		});
        tv_cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                mDialog.dismiss();
            }
        });

        setView();
    }
   

    public void NotCancel(boolean cancel){
        mDialog.setCanceledOnTouchOutside(cancel);
        mDialog.setCancelable(cancel);
    }
    public void show(){
        mDialog.show();
    }

    public void dismiss(){
        mDialog.dismiss();
    }

    /**
     *
     * @author sfshine
     *
     */
    public interface Dialogcallback {
        public void dialogdo();
    }
    public void setCameraDialogCallback(Dialogcallback dialogcallback) {
        this.cameracallback = dialogcallback;
    }
    public void setPhotoDialogCallback(Dialogcallback dialogcallback) {
        this.photocallback = dialogcallback;
    }   
    public void setCanceleDialogCallback(Dialogcallback dialogcallback) {
        this.canceldialogcallback = dialogcallback;
    }
    private void setView(){
       // mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

        mDialog.setContentView(view);

        Window dialogWindow = mDialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.CENTER);
        WindowManager m = ((Activity)mContext).getWindowManager();
        Display d = m.getDefaultDisplay();
        WindowManager.LayoutParams p = dialogWindow.getAttributes();
        //  p.height = (int) (d.getHeight() * 0.25);
        p.width = (int) (d.getWidth() * 0.7);
        dialogWindow.setAttributes(lp);

    }
}
